{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Checkup of User Goals and Devices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, Markdown\n",
    "import snakemd\n",
    "\n",
    "import fitfile\n",
    "import garmindb\n",
    "from garmindb import GarminConnectConfigManager\n",
    "from garmindb.garmindb import GarminDb, Device, DeviceInfo, ActivitiesDb, Activities, ActivityLaps, ActivityRecords, StepsActivities\n",
    "\n",
    "doc = snakemd.new_doc()\n",
    "\n",
    "gc_config = GarminConnectConfigManager()\n",
    "db_params_dict = gc_config.get_db_params()\n",
    "\n",
    "garmin_db = GarminDb(db_params_dict)\n",
    "\n",
    "checkup = garmindb.Checkup(paragraph_func=doc.add_paragraph, heading_func=doc.add_heading)\n",
    "\n",
    "doc.add_heading(\"Goals\", 2)\n",
    "checkup.goals()\n",
    "\n",
    "doc.add_heading(\"Devices with Low Batteries\", 2)\n",
    "\n",
    "devices = Device.get_all(garmin_db)\n",
    "for device in devices:\n",
    "    battery_level = DeviceInfo.get_col_latest_where(garmin_db, DeviceInfo.battery_status,\n",
    "                                                    [DeviceInfo.serial_number == device.serial_number,\n",
    "                                                        DeviceInfo.battery_status != fitfile.field_enums.BatteryStatus.invalid])\n",
    "    if battery_level is fitfile.field_enums.BatteryStatus.low:\n",
    "        doc.add_paragraph(f\"Device {device.manufacturer} {device.product} ({device.serial_number}) has a low battery\")\n",
    "\n",
    "display(Markdown(str(doc)))"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "bfd9857ee3bb42c16b52c1ffe04453343fea53c05fc5f9f2d5ac6a881cdaa36c"
  },
  "kernelspec": {
   "display_name": "Python 3.9.10 ('.venv': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
